namespace CSharpPro._10_6_01;

public class demo2
{
    //
    public void text01() {
        Console.Write("请输入第一个整数：");

        int x = Convert.ToInt32(Console.ReadLine());
        Console.Write("请输入第二个整数：");
        int y = Convert.ToInt32(Console.ReadLine());
        Console.Write("请输入第三个整数：");
        int z = Convert.ToInt32(Console.ReadLine());

        int[] numbers = { x, y, z };
        Array.Sort(numbers);
        Console.WriteLine("排序结果：");
        foreach (int num in numbers)
        {
            Console.WriteLine(num);
        }
       
}
    public void text02() {
           int sum = 0;
           Console.WriteLine("1-100之间符合条件的数字：");

           for (int i = 1; i <= 100; i++)
           {

               bool a = (i % 7 != 0);
               bool b= !i.ToString().Contains('7');

               if (a && b)
               {
                   Console.Write($"{i} ");
                  sum += i;
               }
           }

           Console.WriteLine($"\n\n符合条件数字的总和为：{sum}");
       }
    public void text03()
    {
       for(int i=1;i<=9;i++)
        {
            for (int j = 1; j <= i; j++)
            {
                Console.Write($"{j}*{i}={j*i}\t");
            }
            Console.WriteLine(); 
        }
    }

    public void text04()
    {
        Console.WriteLine("1000以内的完数有：");
        for (int n = 2; n <= 1000; n++)
        {
            int sum = 0;
            for (int i = 1; i <= n / 2; i++)
            {
                if (n % i == 0)
                {
                    sum += i;
                }
            }
            if (sum == n)
            {
                Console.WriteLine(n);
            }
        }
    }

    public void text05()
    {
        Console.Write("请输入一个正整数：");
        int number = int.Parse(Console.ReadLine());
        int digitCount = number.ToString().Length;
        Console.WriteLine($"1. 这是一个{digitCount}位数");
        Console.Write("2. 逆序打印：");
        char[] digits = number.ToString().ToCharArray();
        Array.Reverse(digits);
        Console.WriteLine(new string(digits));
    }

    public void text06()
    {
        Console.Write("请输入菱形的行数（奇数）：");
        int n = int.Parse(Console.ReadLine());
        
        if (n % 2 == 0 || n <= 0)
        {
            Console.WriteLine("错误：行数必须是正奇数！");
            return;
        }
        int a = n / 2 + 1;
        for (int i = 1; i <= n; i++)
        {
            int distance = Math.Abs(i - a);  
            int spaces = distance;            
            int stars = n - 2 * distance;      
            for (int s = 0; s < spaces; s++)
            {
                Console.Write(" ");
            }
            for (int j = 0; j < stars; j++)
            {
                Console.Write("*");
            }
            Console.WriteLine();
        }
    }
}

